package com.coocaa.x.demo.servlets;

import com.coocaa.x.service.litewebserver.webserver.NanoHTTPD;
import com.coocaa.x.service.litewebserver.webserver.servlet.Servlet;

import java.io.InputStream;

/**
 * Created by lu on 15-9-9.
 */
public class WebServlet extends Servlet {
    private ServletInfo info = null;

    @Override
    protected void onCreate() {

    }

    @Override
    protected void onDestroy() {

    }

    @Override
    protected NanoHTTPD.Response onServe(NanoHTTPD.IHTTPSession session) {
        return newChunkedResponse(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_HTML, getResource(session.getUri()));
    }

    @Override
    public synchronized ServletInfo getServletInfo() {
        if (info == null) {
            info = new ServletInfo();
            info.servletName = "web";
            info.vendorName = "web";
            info.versionCode = 1;
            info.versionName = "1.0.0";
        }
        return info;
    }

    @Override
    protected InputStream getResource(String uri) {
        return getResourceFromAssets(uri);
    }
}
